package com.yskj.mwk.config;

import com.yskj.mwk.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://192.168.0.108:8080") // 允许来自 example.com 的请求
                //.allowedOrigins("http://192.168.31.170:8080")
                .allowedMethods("*") // 允许所有方法
                .allowedHeaders("*") // 允许所有头
                .allowCredentials(true); // 允许携带认证信息（如 Cookies）
    }

    @Autowired
    private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器，并指定要拦截的路径和排除的路径
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/manager/**") // 拦截的路径
                .excludePathPatterns("/manager/login_ma/**"); // 排除的路径（可选）
    }
}

